<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const p = new Promise((resolve,reject)=>{
            // resolve控制成功状态
            // 下列代码代表1秒后异步任务状态转为成功
            setTimeout(()=>{
                let data = '数据';
                resolve(data);
            },3000);

            // reject控制失败状态
            // 下列代码代表3秒后异步任务状态为失败
            setTimeout(()=>{
                let err = '数据读取失败';
                reject(err);
            },1000);
        });

        p.then((value)=>{
            //成功调这个函数
            console.log(value);
        },(reason)=>{
            //失败调这个函数
            console.log(reason);
        })
    </script>
</body>
</html>